package v1

import (
	"github.com/gin-gonic/gin"
	"guns-go/model/request"
	"guns-go/model/response"
	"guns-go/service"
)

// @Tags Menu
// @Summary 菜单列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysMenuParam true "请求参数"
// @Success 200 {string} string "{"success":true,"data":{},"message":"请求成功","code":200}"
// @Router /sysMenu/list [get]
func MenuList(c *gin.Context) {

	var M request.SysMenuParam
	_ = c.ShouldBindQuery(&M)

	err, info := service.MenuList(&M)

	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}

	response.OkWithData(info, c)
}

// @Tags Menu
// @Summary 菜单树
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysMenuParam true "请求参数"
// @Success 200 {string} string "{"success":true,"data":{},"message":"请求成功","code":200}"
// @Router /sysMenu/tree [get]
func MenuTree(c *gin.Context) {

	var M request.SysMenuParam
	_ = c.ShouldBindQuery(&M)

	err, info := service.MenuTree(&M)

	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}

	response.OkWithData(info, c)
}

// @Tags Menu
// @Summary 新增菜单
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysMenuParam true "请求参数"
// @Success 200 {string} string "{"success":true,"data":{},"message":"请求成功","code":200}"
// @Router /sysMenu/add [post]
func MenuAdd(c *gin.Context) {

	var M request.SysMenuParam
	_ = c.ShouldBindJSON(&M)

	err := service.MenuAdd(&M)

	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}

	response.Ok(c)
}

// @Tags Menu
// @Summary 修改菜单
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysMenuParam true "请求参数"
// @Success 200 {string} string "{"success":true,"data":{},"message":"请求成功","code":200}"
// @Router /sysMenu/edit [post]
func MenuEdit(c *gin.Context) {

	var M request.SysMenuParam
	_ = c.ShouldBindJSON(&M)

	err := service.MenuEdit(&M)

	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}

	response.Ok(c)
}

// @Tags Menu
// @Summary 删除菜单
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysMenuParam true "请求参数"
// @Success 200 {string} string "{"success":true,"data":{},"message":"请求成功","code":200}"
// @Router /sysMenu/delete [post]
func MenuDelete(c *gin.Context) {

	var M request.SysMenuParam
	_ = c.ShouldBindJSON(&M)

	err := service.MenuDelete(&M)

	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}

	response.Ok(c)
}

// @Tags Menu
// @Summary 授权菜单
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysMenuParam true "请求参数"
// @Success 200 {string} string "{"success":true,"data":{},"message":"请求成功","code":200}"
// @Router /sysMenu/treeForGrant [get]
func TreeForGrant(c *gin.Context) {

	var M request.SysMenuParam
	_ = c.ShouldBindJSON(&M)

	userId := GetUserID(c)

	err, info := service.TreeForGrant(userId, &M, c)

	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.OkWithData(info, c)
}

// @Tags Menu
// @Summary 菜单切换
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysMenuParam true "请求参数"
// @Success 200 {string} string "{"success":true,"data":{},"message":"请求成功","code":200}"
// @Router /sysMenu/change [post]
func MenuChange(c *gin.Context) {

	var M request.SysMenuParam
	_ = c.ShouldBindJSON(&M)

	userId := GetUserID(c)

	err, info := service.GetLoginMenusAntDesign(userId, M.Application)

	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.OkWithData(info, c)
}
